home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / maximus / mpm1_20.zip / ANNOUNCE.CMD next >
OS/2 REXX Batch file  |  1994-07-16  |  10KB  |  281 lines

  1. /* ANNOUNCE.CMD - REXX program to generate a File Announcement
  2. with MPBeta for new files. Version 1.21
  3.  
  4. ver 1.1:  Found an error and in the process of cleaning it up, sped up the
  5. program's execution! Moved the file_desc stuff inside the loop.
  6.  
  7. ver 1.2:  Added format description routines, most borrowed from Craig
  8. Morrison (Thanks!)
  9.  
  10. ver 1.21: Added two lines to add back the space between upload counters:
  11. from ( 0) back to (  0). It was stripped out in formatting.
  12.  
  13.   - 13 July, 1994 by Elliott Goodman, 1:102/1319 - 805-264-0200
  14. */
  15.  
  16. /* check whether RxFuncs are loaded. If not, load them. */       
  17.                                                                  
  18. if RxFuncQuery('SysLoadFuncs') then                              
  19. do                                                               
  20.         call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  21.         call SysLoadFuncs                                        
  22. end                                                              
  23.  
  24. /* Just to let the user know what's going on.... */
  25.  
  26. say 'Searching thru file areas for new files to announce.'
  27. say 'Please wait....';
  28. say ' ';
  29.  
  30.  
  31. /* create a tracking file */
  32. report = 'd:\lora\file\mpbeta\announce.txt'
  33.  
  34. /* delete old tracking file, if present */
  35. call SysFileDelete(report)
  36.  
  37. m_txt = 'Report of ANNOUNCE.CMD activity'
  38. call lineout report, m_txt
  39. m_txt = date('U')
  40. call lineout report, m_txt
  41. m_txt = ''
  42. call lineout report, m_txt
  43.  
  44. /* get today's date, create an index from it */
  45. day_index = SPECIFIED_DATE_IN_DAYS( DATE('U') )                        
  46.  
  47. /* set some defaults */
  48.  
  49. nfile.0 = 0
  50. files.0 = 0                /* will increment */
  51. file_index = 0
  52.  
  53. lmargin = 16         /* how far from the left margin the ED Marker should be */
  54. llength = 45                 /* this is how long each line segment should be */
  55. EDMarker = '>'        /* Set EDMarker to your extended description character */
  56.                                                                                
  57. spaces = SubStr(Copies(' ', 80), 1, lmargin)||EDMarker||' '                    
  58.  
  59. /* set up the array elements of FILES which will be used by
  60. MPM_AnnounceFiles() at the end of all this processing.
  61. See TANN.CMD included with MPBeta for details.   */
  62.  
  63. files.msgpath = 'D:\LORA\MSG\USERS'
  64. files.msgtype = 'SQUISH'
  65. files.msgflag = 'CRASH'
  66. files.to = 'ALL'
  67. files.toaddr = '1:102/1316.0'
  68. files.header = 'New files online at Miles Enterprises BBS'
  69. files.from = 'Elliott Goodman'
  70. files.fromaddr = '1:102/1319.0'
  71. files.footer = '- Elliott'
  72.  
  73. /* your origin info */
  74. files.origin = 'Miles Enterprises * 805-264-0200 *'
  75.  
  76. /* my first 44 areas are on the CD so I start with 44 (and increment it
  77. immediately.) This saves time since the CD is slow. */
  78. mpmarea = 44    
  79.  
  80. do forever                /* we'll bail out after the last area */
  81.    mpmarea = MPM_QueryArea(mpmarea)    /* look at next area */
  82.    if mpmarea = 'ERROR' then do
  83.       leave                /* this will bail us out */
  84.       end /* if error (past last file area) */
  85.  
  86. /* get drive/subdir of next file area */
  87.    area_path = MPM_QueryAreaInfo(mpmarea, '1')
  88.  
  89. /* notify user of our progress */
  90.    say area_path ;
  91.  
  92. /* use SysFileTree here to check for new files */
  93.    call SysFileTree area_path, stuff, 'F'
  94.  
  95. /* reset before each file area */
  96.    found_new = 0
  97.    nfile.0 = 0
  98.  
  99. /* assume at least one file in the file area */
  100.    do i = 1 to stuff.0        /* cycle thru files in one area */
  101.  
  102. /* get info on each file in the area */
  103.    parse var stuff.i,
  104.          file_date,
  105.          file_time,
  106.          file_size,
  107.          file_attr,
  108.          file_name
  109.  
  110. /* remove trailing space */
  111.    file_name = strip( file_name )
  112.  
  113. /* remove drive/subdir info from filename */
  114.    parse var file_name (area_path) file_name
  115.  
  116. /* convert to caps, just in case */
  117.    file_name = translate( file_name )
  118.  
  119. /* get extention. We don't want to announce FILES.BBS or FILES.BAK! */
  120.    parse var file_name junk '.' extn
  121.  
  122.    if extn = 'BAK' then do
  123.       iterate
  124.       end
  125.  
  126.    if extn = 'BBS' then do
  127.       iterate
  128.       end
  129.  
  130. /* test if next file is dated today, hence NEW */
  131.    file_test = SPECIFIED_DATE_IN_DAYS( file_date )
  132.    if file_test = day_index then do
  133.  
  134. /* here's where the ver. 1.1 code makes it's major changes. Store the
  135. files that are new and do them all at once for each area */
  136.       found_new = 1
  137.       nfile.0 = nfile.0 + 1
  138.       t_index = nfile.0
  139.       nfile.t_index = file_name
  140.       end /* if file_test = day_index */
  141.  
  142.    end /* do i = 1 to stuff.0 */
  143.  
  144. /* now, if we found one or more new files in this area... */
  145.    if found_new = 1 then do
  146.  
  147. /* we have to open the files.bbs file so we can get the
  148. description */
  149.       retval = MPM_OpenArea(mpmarea)
  150.  
  151. /* this just gives the system time to open the file */
  152.       Call SysSleep 3
  153.  
  154. /* ....cycle thru the new files for this area */
  155.       do k = 1 to nfile.0
  156.  
  157. /* continue storing elements in FILES */
  158.          file_index = file_index + 1
  159.          files.0 = files.0 + 1
  160.          files.file_index.path = area_path
  161.          files.file_index.file = nfile.k
  162.  
  163.          text = MPM_QueryFileInfo(mpmarea, nfile.k, '3')
  164.  
  165. /* just in case no description was Tic'd... */
  166.          if text = 'ERROR' then do
  167.             text = 'No Description!'
  168.             end
  169.  
  170. /* here's where we format the file description!   */
  171.  
  172. /* Translate all CRs, LFs and Extended Description Markers into spaces */
  173.          ntext = Translate(text, '   ', x2c('0d')||x2c('0a')||EDMarker)                 
  174.          
  175.          text = GetOneLine(llength, ntext)                    
  176.          ntext = Space(DelWord(ntext, 1, Words(text)), 1)     
  177.          Do While Length(ntext) \= 0                          
  178.             wText = GetOneLine(llength, ntext)               
  179.             text = text||x2c('0d')||x2c('0a')||spaces||wText 
  180.             ntext = Space(DelWord(ntext, 1, Words(wText)), 1)
  181.             End
  182.  
  183. /* the following two lines replace the extra space between
  184. parentesis that was removed: (  0) */
  185.          text = overlay(' ',text,1,1)
  186.          text = '('||text            
  187.  
  188.          retval = MPM_SetFileInfo(mpmarea, nfile.k, '2', text)
  189.  
  190.          text = Space(Translate(text, ' ', '>'), 1)
  191.          files.file_index.desc = text
  192.          end /* do k to nfile.0 */
  193.  
  194. /* close the files.bbs file to avoid problems */
  195.       retval = MPM_CloseArea(mpmarea)
  196.       end /* if  found = 1 */
  197.  
  198.    end /* do forever */
  199.  
  200. /* if no new files: exit */
  201. if files.0 = 0 then do
  202.    m_txt = 'No new files found'
  203.    call lineout report, m_txt
  204.    exit
  205.    end
  206.  
  207. /* there are new files. Save the info so we can play
  208. with the descriptions when we wake up <g> */
  209.  
  210. m_txt = 'List of New Files'
  211. call lineout report, m_txt
  212. m_txt = ' '
  213. call lineout report, m_txt
  214.  
  215. do j = 1 to files.0
  216.    m_txt = 'File Path = ' files.j.path
  217.    call lineout report, m_txt
  218.    m_txt = 'File Name = ' files.j.file
  219.    call lineout report, m_txt
  220.    m_txt = 'File Description = ' files.j.desc
  221.    call lineout report, m_txt
  222.    m_txt = ' '
  223.    call lineout report, m_txt
  224.    end  
  225.  
  226. /* actually make the announcement */
  227. retval = MPM_AnnounceFiles('files')
  228.  
  229. m_txt = files.0 'new files announced!'
  230. call lineout report, m_txt
  231.  
  232. /* and we're done */
  233. exit
  234.  
  235. /*------------------------------------------------*/                 
  236. /* Convert calendar date to consistent date index                  */
  237. /*------------------------------------------------*/                 
  238. SPECIFIED_DATE_IN_DAYS:                                              
  239.    Procedure                                                         
  240.                                                                      
  241. parse arg,                                                           
  242.    mm '/',                                                           
  243.    dd '/',                                                           
  244.    yy                                                                
  245.                                                                      
  246. days_by_month = '31 28 31 30 31 30 31 31 30 31 30 31'                
  247. current_number_of_days = (yy * 365) + dd                             
  248. do m = 1 while m < mm                                                
  249.    current_number_of_days = current_number_of_days +,                
  250.       WORD( days_by_month, m )                                       
  251. end                                                                  
  252. return current_number_of_days                                        
  253.  
  254. /*   This subroutine and all format description routines written by
  255.       Craig Morrison, author of MaxFilePM.
  256.     GetOneLine takes a variable length string and returns a blank delimited   
  257.     string that is a substring of inText and is no longer than llen           
  258.     characters.                                                               
  259.                                                                               
  260.     A single word that is longer than llen is simply truncated at llen when it
  261.     would be the only word in a line segment and not wrappable. Its cheesy and
  262.     cheap, but hey, it works.. ;-)                                            
  263. */                                                                            
  264.  
  265. GetOneLine:                                        
  266.                                                    
  267.     Parse Arg llen, inText                         
  268.                                                    
  269.     cText = ''                                     
  270.     Do While Length(cText' 'Word(inText, 1)) < llen
  271.         cText = cText' 'Word(inText, 1)            
  272.         inText = DelWord(inText, 1, 1)             
  273.         If inText = '' Then Leave                  
  274.     End                                            
  275.                                                    
  276.     if cText = '' Then Do                          
  277.         cText = Left(inText, llen)                 
  278.     End                                            
  279.                                                    
  280. Return Space(cText, 1)                             
  281.